﻿using LucyGrid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LucyGridSniffer
{
	class Program
	{
		static void Main(string[] args)
		{
			GridUtils.EnableLog = -1;
			new Program().Run();
		}
		void Run(){
			var lck = this;
			System.Text.RegularExpressions.Regex regex = null; 
			new GridComm().StartListener((m) =>
			{
				if (regex != null)
				{
					lock (lck)
					{
						var match = regex.Match(m);
						if (match.Success)
							Console.WriteLine(m);
					}
				}else
					Console.WriteLine(m);
			});
			string line = null;
			while ((line = Console.ReadLine()) != "quit")
			{
				lock (lck) {
					regex = string.IsNullOrEmpty(line) ? null :
							new System.Text.RegularExpressions.Regex(line);
				}
			}
		}
	}
}
